//
//  YSDevicesVC.m
//  ocdemo
//
//  Created by mac on 2025/3/9.
//

#import "YSDevicesVC.h"

@interface YSDevicesVC ()

@end

@implementation YSDevicesVC

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.tabBarItem.title=@"萤石";
        self.tabBarItem.image = [UIImage imageNamed:@"icon.bundle/page@2x.png"];
        self.tabBarItem.selectedImage = [UIImage imageNamed:@"icon.bundle/page_selected@2x.png"];
    
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithRed:0.95 green:0.95 blue:0.96 alpha:1.0];
    
    // 创建顶部搜索栏
    [self setupSearchBar];
    
    // 创建天气和通知区域
    [self setupWeatherAndNotification];
    
    // 创建设备卡片
    [self setupDeviceCards];
}

- (void)setupSearchBar {
    UIView *searchContainer = [[UIView alloc] initWithFrame:CGRectMake(15, 60, self.view.bounds.size.width - 30, 44)];
    searchContainer.backgroundColor = [UIColor whiteColor];
    searchContainer.layer.cornerRadius = 8;
    searchContainer.layer.masksToBounds = YES;
    
    UISearchBar *searchBar = [[UISearchBar alloc] initWithFrame:searchContainer.bounds];
    searchBar.placeholder = @"搜索设备";
    searchBar.searchBarStyle = UISearchBarStyleMinimal;
    [searchContainer addSubview:searchBar];
    
    [self.view addSubview:searchContainer];
}

- (void)setupWeatherAndNotification {
    // 天气信息
    UILabel *weatherLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 120, 60, 80, 44)];
    weatherLabel.text = @"28°C 晴";
    weatherLabel.textColor = [UIColor darkGrayColor];
    weatherLabel.textAlignment = NSTextAlignmentRight;
    weatherLabel.font = [UIFont systemFontOfSize:14];
    [self.view addSubview:weatherLabel];
    
    // 通知图标
    UIImageView *notificationIcon = [[UIImageView alloc] initWithFrame:CGRectMake(self.view.bounds.size.width - 40, 60, 24, 24)];
    notificationIcon.image = [UIImage systemImageNamed:@"bell.fill"];
    notificationIcon.tintColor = [UIColor darkGrayColor];
    [self.view addSubview:notificationIcon];
}

- (void)setupDeviceCards {
    // 第一个设备卡片 (加密状态)
    UIView *deviceCard1 = [self createDeviceCardWithFrame:CGRectMake(15, 120, self.view.bounds.size.width - 30, 120)
                                                deviceName:@"CP1(G44680070)"
                                                 statusText:@"视频已加密"
                                                  isOnline:YES
                                                  isLocked:YES];
    [self.view addSubview:deviceCard1];
    
    // 第二个设备卡片 (离线状态)
    UIView *deviceCard2 = [self createDeviceCardWithFrame:CGRectMake(15, 260, self.view.bounds.size.width - 30, 120)
                                                deviceName:@"CB2(BF2163057)"
                                                 statusText:@"离线 3小时前"
                                                  isOnline:NO
                                                  isLocked:NO];
    [self.view addSubview:deviceCard2];
}

- (UIView *)createDeviceCardWithFrame:(CGRect)frame
                           deviceName:(NSString *)name
                          statusText:(NSString *)status
                           isOnline:(BOOL)isOnline
                           isLocked:(BOOL)isLocked {
    UIView *card = [[UIView alloc] initWithFrame:frame];
    card.backgroundColor = [UIColor whiteColor];
    card.layer.cornerRadius = 8;
    card.layer.masksToBounds = YES;
    
    // 设备名称
    UILabel *nameLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, 15, card.bounds.size.width - 30, 24)];
    nameLabel.text = name;
    nameLabel.font = [UIFont boldSystemFontOfSize:18];
    [card addSubview:nameLabel];
    
    // 状态图标和文本
    UIImageView *statusIcon = [[UIImageView alloc] initWithFrame:CGRectMake(15, 50, 20, 20)];
    UILabel *statusLabel = [[UILabel alloc] initWithFrame:CGRectMake(45, 50, card.bounds.size.width - 60, 20)];
    
    if (isLocked) {
        statusIcon.image = [UIImage systemImageNamed:@"lock.fill"];
        statusIcon.tintColor = [UIColor systemOrangeColor];
        statusLabel.textColor = [UIColor systemOrangeColor];
    } else if (!isOnline) {
        statusIcon.image = [UIImage systemImageNamed:@"wifi.slash"];
        statusIcon.tintColor = [UIColor systemGrayColor];
        statusLabel.textColor = [UIColor systemGrayColor];
    } else {
        statusIcon.image = [UIImage systemImageNamed:@"checkmark.circle.fill"];
        statusIcon.tintColor = [UIColor systemGreenColor];
        statusLabel.textColor = [UIColor systemGreenColor];
    }
    
    statusLabel.text = status;
    statusLabel.font = [UIFont systemFontOfSize:14];
    
    [card addSubview:statusIcon];
    [card addSubview:statusLabel];
    
    return card;
}

@end
